package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.entity.Student;
import com.itheima.entity.StudentQueryParam;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public PageBean page(StudentQueryParam param) {
        PageHelper pageHelper=new PageHelper();
        pageHelper.startPage(param.getPage(),param.getPageSize());

        List<Student> studentList=studentMapper.page(param);

        Page page=(Page)studentList;

        PageBean pageBean=new PageBean(page.getTotal(),page.getResult());

        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        studentMapper.delete(ids);
    }

    @Override
    public void insert(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.insert(student);
    }

    @Override
    public Student getById(Integer id) {


        return studentMapper.getById(id);
    }

    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }

    @Override
    public void updateV(Integer id, Integer score) {
        studentMapper.updateV(id,score);
    }
}
